package service.Impl;

import dao.mapper.ClientMapper;
import org.apache.ibatis.session.SqlSession;
import service.IClientService;
import utils.SqlSessionUtil;
import vo.Client;

import java.util.ArrayList;
import java.util.List;

public class IClientServiceImpl implements IClientService {
    SqlSession sqlSession = new SqlSessionUtil().sqlSession;
    ClientMapper clientMapper = sqlSession.getMapper(ClientMapper.class);
    @Override
    public void addClient(Client client) {
        clientMapper.addClient(client);
        sqlSession.commit();

    }

    @Override
    public boolean checkClient(String phoneNumber, String password) {
        Client client = clientMapper.getClientByNumber(phoneNumber);
        if(client != null && client.getPassword().equals(password)){
            return true;
        }
        return false;
    }

    @Override
    public boolean checkPhoneNumber(String phoneNumber) {
        Client client = clientMapper.getClientByNumber(phoneNumber);
        if(client != null){
            return true;
        }
        return false;
    }

    @Override
    public Client selectClient(String phoneNumber) {
        Client client=clientMapper.getClientByNumber(phoneNumber);
        return client;
    }

    @Override
    public List<Client> selectCs() {
        List<Client>clients=new ArrayList<>();
        clients=clientMapper.selects();
        return clients;
    }
}
